package com.wc.codeforces.思维.pspspsps;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/12/21 9:24
 * @description
 * https://codeforces.com/contest/2049/problem/B
 */
public class Main {
    /**
     * 思路：
     * 考虑:
     * p 后面是一定不能有 s的, p 代表前面有 1, s 代表后后面有 1, 矛盾了
     * s 一定是在 p 的前面, (1) s (2) p (3), 如果 1, 3 同时存在, 那他们一定相等, 那样就矛盾了, 说明1, 3最多有一个存在
     * 剩下的都不满足
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 510;
    static char[] s;
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            s = (" " + sc.next()).toCharArray();
            // 找到左边第一个 s, 找到左边第一个 p
            // 找到右边第一个 s, 找到右边第一个 p
            int sts = 1, edp = n;
            int stp = 1, eds = n;
            while (sts <= n && s[sts] != 's') sts++;
            while (edp >= 1 && s[edp] != 'p') edp--;
            while (stp <= n && s[stp] != 'p') stp++;
            while (eds >= 1 && s[eds] != 's') eds--;
            // 表示最多只有一种 s / p 存在
            if (sts == n + 1 || edp == 0) out.println("YES");
            // p 后面有 s
            else if (stp < eds) out.println("NO");
            // (1) s (2) p (3) 说明1, 3最多有一个存在
            else if (eds == 1 || stp == n) out.println("YES");
            else out.println("NO");
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

